/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ken
 * Date: 2023-12-31
 * Time: 15:43
 */
public class MyCircularQueue {
    private final int[] elme;
    private int front;
    private int crear;

    public MyCircularQueue(int m) {
        this.elme = new int[m+1];
    }
    //  入队列
    public boolean inque (int q) {
    if(isfull()) {
        return false;
    }
    elme[crear] = q;
    crear = (crear + 1) % elme.length;
    return true;
    }
    //出队列
    public boolean runque () {
    if(isEmpty()) {
        return false;
    }
    elme[front] = 0;
    front = (front+1) % elme.length;
    return true;
    }
    //获取队列的头
    public int inheadque (){
        if(isEmpty()) {
            return -1;
        }
        return elme[front];
    }
    //获取队列的尾巴
    public int weique () {
        int index = 0;
        if(isEmpty()) {
            return  -1;
        }
        index = (crear == 0)? elme.length-1 : crear - 1;
        return elme[index];
    }
    //判断队列是否为空
    private boolean isEmpty(){
        return front == crear;
    }
    // 检查是否满了
    private boolean isfull() {
       return  (crear+1) % elme.length == front;  //精华所在
    }

}
